#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "stduser.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    buildUI();
    buildSignalSlots();
    ui->toolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
}

void MainWindow::buildUI()
{
    labFile = new QLabel(this);
    labFile->setMinimumWidth(150);
    labFile->setText("文件名:");
    ui->statusbar->addWidget(labFile);

    progressBar = new QProgressBar(this);
    progressBar->setMaximumWidth(200);
    progressBar->setMinimum(5);
    progressBar->setMaximum(50);
    ui->statusbar->addWidget(progressBar);

    spinFontSize = new QSpinBox(this);
    spinFontSize->setMinimum(5);
    spinFontSize->setMaximum(50);
    ui->toolBar->addWidget(spinFontSize);

    comboFontName = new QFontComboBox(this);
    comboFontName->setMinimumWidth(150);
    ui->toolBar->addWidget(comboFontName);

    ui->toolBar->addSeparator();
    ui->toolBar->addAction(ui->act_About);

    fourWidget = new FourP11();
    ui->mainTabWidget->addTab(fourWidget,"TBLW");
    ui->mainTabWidget->setStyleSheet(
        "QTabWidget::tab-bar{alignment:center;}"
    );

    
}

void MainWindow::buildSignalSlots()
{
    connect(ui->act_About, &QAction::triggered, this, &MainWindow::showAppMsg);
    connect(ui->act_openFile, &QAction::triggered, this, &MainWindow::openFile);

    connect(spinFontSize,SIGNAL(valueChanged(int)),this,SLOT(do_fontSize_changed(int))); 
    connect(comboFontName,&QFontComboBox::currentFontChanged, 
 this, &MainWindow::do_fontSelected);
}

// 打开文件
void MainWindow::openFile()
{
    qDebug()<< "open file";
    return;
}

void MainWindow::showAppMsg()
{
    qDebug()<< "show app msg" ;
    return;
}

void MainWindow::do_fontSize_changed(int fontSize){
    qDebug()<<"font size is:"<<fontSize;
    progressBar->setValue(fontSize);

}
void MainWindow::do_fontSelected(const QFont &font){
   qDebug()<<"font is :"<<font.family();
    
}

MainWindow::~MainWindow()
{
    delete ui;
}
